﻿/// <reference path="../../admin/theme.scss" />

$dg-border: #dee2e6;
$dg-even: mix($light, #fff, 60%);
$dg-hover: darken(#f2f7fb, 0.5%);

.spa-layout {
    #content {
        // TODO: (core) Move this selector enhancement with $content-padding-x (instead of 30px) to ported scss file
        padding-bottom: 30px;
    }
}


// TODO: (core) Move to applicable place later
// -----------------------------------------
input.form-control-plaintext {
    outline: 0;
}
// END TODO
// -----------------------------------------


// Common
// -----------------------------------------

.datagrid-root {
    --dg-border-color: #{$dg-border};
    --dg-header-bg: #{$light};
    //--dg-header-bg: #fff;
    --dg-footer-bg: #{$white};
    --dg-pager-bg: #{$light};
    --dg-toolbar-bg: #{$light};
    //--dg-toolbar-bg: #{mix($light, #fff)};
    --dg-row-bg: #fff;
    --dg-row-even-bg: #fff;
    --dg-row-hover-color: #{$dg-hover};
    --dg-row-active-color: #{$dg-hover};
    --dg-row-inactive-color: #{lighten($light, 1.5%)};
    --dg-cell-padding: 13px 16px;
    --dg-cell-align: center;
    --dg-cell-justify: flex-start;
    --dg-search-width: 350px;
    position: relative;
    overflow: hidden;
    border: 1px solid var(--dg-border-color);
    box-shadow: 0 0 5px rgba(#000, 0.08);
    flex-grow: 1;
    width: 100%;
}

.datagrid {
    display: flex;
    flex-flow: row;
    height: 100%;
    opacity: 0;
    transform: scale(1.0124, 1.0124);
    transition-property: transform, opacity;
    transition-duration: 0.4s;
    transition-timing-function: cubic-bezier(0, 0.55, 0.45, 1); // easeOutCirc

    &.datagrid-ready {
        opacity: 1 !important;
        transform: scale(1, 1) !important;
    }
}

.datagrid-loader,
.dg-blocker {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 999;
}

.datagrid-loader {
    background-color: #fff;

    .datagrid-ready + & {
        display: none;
    }
}

.dg-grid {
    position: relative;
    display: flex;
    flex-flow: column;
    left: 0;
    width: 100%;
    transition-property: left, width;
    transition-duration: 0.2s;
    transition-timing-function: ease-in-out;
    z-index: 1;

    .dg-search.show + & {
        left: var(--dg-search-width);
        width: calc(100% - var(--dg-search-width));
    }
}

.dg-blocker {
    background-color: transparent;
}

.dg-no-data > td {
    grid-column: 1 / -1;
}

.dg-table-wrapper {
    position: relative;
    flex-grow: 1;
    overflow: auto;
    background-color: #fff;
}

.dg-table {
    position: relative;
    width: auto;
    min-width: 100%;
    //background-color: var(--dg-border-color);
    background-color: #fff;
    display: grid;
    gap: 0;

    .dg-thead,
    .dg-tbody,
    .dg-tfoot,
    .dg-tr {
        display: contents;
    }

    .dg-th,
    .dg-td {
        padding: 0;
        position: relative;
    }

    .dg-td {
        background-color: var(--dg-row-bg);
    }

    .dg-th {
        position: sticky;
        top: 0;
        background-color: var(--dg-header-bg);
        border-bottom: 1px solid var(--dg-border-color);
        z-index: 2;
        user-select: none;
        overflow-x: hidden; // Removes annoying x-scrollbar
    }

    .dg-tbody > tr.even > td {
        background-color: var(--dg-row-even-bg);
    }

    .dg-tr.active,
    .dg-tr.dg-edit-row {
        --dg-row-bg: var(--dg-row-active-color) !important;
        --dg-row-even-bg: var(--dg-row-active-color) !important;
    }

    .dg-tr.inactive {
        --dg-row-bg: var(--dg-row-inactive-color) !important;
        --dg-row-even-bg: var(--dg-row-inactive-color) !important;
    }

    &.dg-resizing {
        cursor: col-resize;
    }

    .dg-tr-foot > td {
        background-color: var(--dg-footer-bg);
        background-color: darken($light, 1%);
        z-index: 6;
        overflow-x: hidden;
    }

    .dg-tr-foot.sticky > td {
        position: sticky !important;
        bottom: 0;
        border-top: 1px solid var(--dg-border-color);
    }
}

.dg-striped {
    --dg-row-even-bg: #{$dg-even};
}

.dg-hover > .dg-tbody > .dg-tr:hover:not(.dg-no-data, .dg-tr-detail) {
    --dg-row-bg: var(--dg-row-hover-color);
    --dg-row-even-bg: var(--dg-row-hover-color);
}

.dg-cell-header {
    //line-height: 1.2;
}

.dg-cell {
    position: relative;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: var(--dg-cell-padding);
    border-top: 1px solid transparent;
    border-bottom: 1px solid transparent;
    display: flex;
    //width: 100%;
    height: 100%;
    align-items: var(--dg-cell-align);
    justify-content: var(--dg-cell-justify);

    &.dg-cell-wrap {
        white-space: normal;

        p:last-child {
            margin-bottom: 0;
        }
    }
}

.dg-cell-spacer {
    padding-left: 0;
    padding-right: 0;
}

.dg-icon + * {
    padding-left: 6px;
}

.dg-cell-value {
    overflow: hidden;
    text-overflow: ellipsis;
}

.dg-vborders {
    > thead > tr > .dg-th,
    > tbody > tr > .dg-td {
        border-bottom: 1px solid var(--dg-border-color);
    }
}

.dg-hborders {
    > thead > tr > .dg-th,
    > tbody > tr > .dg-td,
    > tfoot > tr > .dg-td {
        border-right: 1px solid var(--dg-border-color);

        &:last-child {
            border-right-width: 0;
        }
    }
}

.dg-hborder-0 {
    border-right-width: 0 !important;
}


// Toolbar
// -----------------------------------------

.dg-toolbar {
    background-color: var(--dg-toolbar-bg);
    border-bottom: 1px solid var(--dg-border-color);
    padding: 0.375rem;
}

.dg-toolbar .btn {
    position: relative;
    padding-left: 0.6rem;
    padding-right: 0.6rem;
}

.dg-toolbar-group {
    position: relative;
    display: inline-flex;
    flex-wrap: nowrap;
    align-items: center;
    vertical-align: middle;
    padding-right: 0.5rem;
    margin-right: 0.5rem;
    border-right: 1px solid var(--dg-border-color);

    &.omega,
    &:last-child {
        border-right-width: 0;
        padding-right: 0;
        margin-right: 0;
    }

    &.omega {
        margin-left: auto;
    }
}

.dg-toolbar-badge {
    position: absolute !important;
    right: 2px;
    top: 2px !important;
    font-size: 10px;
}

.dg-commands-toggle {
    display: flex;
}

.dg-commands-dropdown .disabled,
.dg-toolbar .btn.disabled {
    pointer-events: none;
}


// Search Panel
// -----------------------------------------
.dg-search {
    position: absolute;
    opacity: 0;
    left: 0;
    top: 0;
    height: 100%;
    width: var(--dg-search-width);
    border-right: 1px solid var(--dg-border-color);
    transform: translateX(-30px);
    transition: all 0.2s ease-in-out;
    z-index: 0;
    overflow-y: auto;

    &.show {
        opacity: 1;
        transform: translateX(0);
    }
}

.dg-search-header {
    display: flex;
    align-items: center;
    height: 49px;
    border-bottom: 1px solid var(--dg-border-color);
}

.dg-search-body {
}


// Sorting
// -----------------------------------------

.dg-table:not(.dg-resizing) .dg-sortable {
    cursor: pointer;
    //transition: background-color 0.1s;

    &:hover {
        background-color: rgba(#000, 0.035);
    }

    &:active, &.show {
        background-color: rgba(#000, 0.075);
    }
}


// Resizing & Column reordering
// -----------------------------------------

.dg-resize-handle {
    position: absolute;
    display: block;
    top: 0;
    right: -4px;
    bottom: 0;
    width: 10px;
    opacity: 0;
    transform: scaleX(0);
    cursor: col-resize;
    transition: all 0.2s ease-in-out;

    &:after {
        position: absolute;
        content: ' ';
        width: 3px;
        top: 0;
        bottom: 0;
        left: 3px;
        background-color: var(--dg-border-color);
    }

    thead:hover & {
        opacity: 0.65;
        transform: scaleX(1);
    }

    &:hover,
    .dg-resizing & {
        opacity: 1 !important;
    }
}

.dg-drop-indicator {
    position: absolute;
    display: block;
    width: 10px;
    z-index: 9999;
    transform: translateX(-50%);
    pointer-events: none;

    &:before,
    &:after {
        position: absolute;
        display: block;
        content: '';
        width: 0;
        height: 0;
        left: 0;
        border-left: 5px solid transparent;
        border-right: 5px solid transparent;
    }

    &:before {
        // Arrow down
        border-top: 5px solid $body-color;
        top: 0;
        transform: translateY(-200%);
    }

    &:after {
        // Arrow up
        border-bottom: 5px solid $body-color;
        bottom: 0;
        transform: translateY(200%);
    }
}


// Pinned columns
// -----------------------------------------

.dg-col-pinned {
    position: sticky !important;
    overflow-x: visible !important;
    z-index: 5;

    &.dg-th {
        z-index: 10;
    }

    &.alpha {
        left: 0;
    }

    &.alpha + .alpha {
        // Detail view toggler beneath selector
        left: 48px;
    }

    &.omega {
        right: 0;
    }
}


// Row selection & Detail view
// -----------------------------------------

.dg-col-selector {
    display: flex;
    justify-content: center;

    .dg-cell + .dg-cell {
        padding-left: 8px;
    }
}

.dg-cell-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    //display: block;
    margin: 0;
}

.dg-cell-selector-checkbox {
    cursor: pointer;
}

.dg-cell-detail-toggle {
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.12s ease-in-out;

    &:hover,
    .dg-tr.expanded & {
        opacity: 1;
    }

    .dg-tr.expanded & > i {
        transform: rotate(90deg);
    }
}


// Inline Edit
// -----------------------------------------

.dg-edit-row {
    .dg-cell {
        border-color: $primary;
    }

    .field-validation-valid {
        display: none;
    }

    .input-validation-error {
        position: absolute;
        top: 0;
        background-color: #fff;
        color: var(--danger);
        border: 1px solid #fccac7;
        padding: 4px 8px;
        border-radius: 2px;
        width: auto;
        transform: translateY(-120%);
        z-index: 1000;
        white-space: nowrap;
        text-overflow: ellipsis;
        --shadow-intensity: 0.75 !important;
    }
}

.dg-cell-edit {
    padding: 0 4px;
    justify-content: center !important;
    //align-items: center !important;
    align-items: stretch !important;
    overflow: visible;
    flex-flow: column;
}

.dg-cell-edit-controls {
    display: flex;
    justify-content: center;

    > .select2 {
        width: 100%;
    }

    .select2-selection {
        --select2-caret-width: 1.5rem !important;
    }

    .numberinput-group {
        --ni-addon-width: 1.5rem !important;
    }
}


// Paging
// -----------------------------------------

.dg-pager {
    padding: 4px;
    background-color: var(--dg-pager-bg);
}

.dg-pager-top {
    border-bottom: 1px solid $dg-border;
}

.dg-pager-bottom {
    border-top: 1px solid $dg-border;
}

.dg-page {
    padding: 8px 6px;
    color: inherit;
}

a.dg-page {
    padding: 5px 10px;
    font-weight: normal;

    &.disabled {
        pointer-events: none;
        opacity: 0.4;
    }
}

.dg-page-refresh-wrapper {
    border-right: 1px solid $dg-border;
    text-align: center;
    margin-right: 6px;
}

.dg-page-refresh {
    margin-right: 6px;
    margin-left: 2px;
}

.dg-page-number {
    &.active {
        pointer-events: none;
    }
}

.dg-page-size-chooser + .dropdown-menu {
    min-width: initial;
}


// Scrolling
// -----------------------------------------

.dg-scrollable .dg-col-pinned {
    &.alpha {
        box-shadow: inset -1px 0 0 var(--dg-border-color);
        border-right: 1px solid var(--dg-border-color);
    }

    &.omega {
        box-shadow: inset 1px 0 0 var(--dg-border-color);
        border-left: 1px solid var(--dg-border-color);
    }

    &:before {
        position: absolute;
        display: block;
        content: "";
        pointer-events: none;
        width: 10px;
        right: -10px;
        top: 0;
        bottom: 0;
        background: linear-gradient(270deg, transparent, rgba(#000, .05));
    }

    &.omega:before {
        right: initial;
        left: -10px;
        background: linear-gradient(90deg, transparent, rgba(#000, .05));
    }
}


.dg-page-number,
.dg-page-size-chooser,
span.dg-page {
    font-size: 13px;
}


// Tools
// -----------------------------------------

.dg-tools-dropdown {
    min-width: 250px;
    //max-width: 350px;
    width: auto;
    max-height: 100vh;
    overflow-y: auto;
    font-size: 13px;

    .switch {
        padding-top: 5px;
        padding-bottom: 5px;
        --switcher-w: 2rem;
        --switcher-h: 1rem;
    }

    select {
        height: 28px;
        padding: 0 4px;
    }
}


// Row commands
// -----------------------------------------

.dg-row-edit-commands {
    width: 100%;
    height: 100%;

    > .btn {
        display: flex;
        align-items: center;
        justify-content: center;
        height: 50%;
        padding: 0 !important;
        > i {
            font-size: 10px !important;
        }
    }
}


.dg-tools-columns {
    display: grid;
    grid-template-columns: minmax(100px, auto) minmax(100px, auto);
    grid-gap: 0 15px;
}

.dg-column-toggle {
    max-width: 150px;
}


// RTL
// -----------------------------------------

[dir=rtl] {
    .dg-page-refresh {
        border-left: 1px solid $dg-border;
        border-right: none;
    }

    .dg-col-pinned.alpha {
        left: initial;
        right: 0;
    }

    .dg-col-pinned.omega {
        left: 0;
        right: initial;
    }

    .dg-icon + * {
        padding-left: 0;
        padding-right: 6px;
    }
}
